using System.Collections.Generic;
using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.GenerateEntity, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_GenerateEntity : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.GenerateEntity;

        public override string name => LevelEditorConst.GenerateEntity;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.GenerateEntity, "实体来源(实体id，0为当前实体)")]
        public int configID;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.GenerateEntity, "EntityInteractType表ID(交互类型)")]
        public int interactType;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.GenerateEntity, "生成到玩家身边(是则生成位置不生效)")]
        public int bornNearPlayer;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.GenerateEntity, "生成位置")]
        public Vector3 pos;
        [InspectorName("生成时朝向rotationY")] public int rotationY;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.GenerateEntity, "添加实体tag")]
        public List<ushort> tags;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            return new LevelServiceExecutionCustom_GenerateEntity()
            {
                configID = this.configID,
                interactType = this.interactType,
                pos = new Int3(this.pos * 100),
                bornNearPlayer = this.bornNearPlayer,
                rotationY = this.rotationY,
                tags = this.tags
            };
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_GenerateEntity rNode)
            {
                this.configID = rNode.configID;
                this.interactType = rNode.interactType;
                this.pos = rNode.pos;
                this.bornNearPlayer = rNode.bornNearPlayer;
                this.rotationY = rNode.rotationY;
                this.tags = rNode.tags;
            }
        }
    }
}